#include "..\Inc\Includes.h"
/***************************************************************************************
	Model		: Knob
	Description	: Knob code
	Author		: Along
	Create Time	: 2022-02-11
	Version ID  : 0.1
****************************************************************************************/

_static bool clockwise = false;
_static bool anticlockwise = false;

void Knob_CheckForInt(bool level)
{
    if(level == GPIO_CHECK)
       anticlockwise = true;//clockwise = true;
    else
       clockwise = true;//anticlockwise = true;
}

void Knob_Process(s32 para)
{
		para = para;   
    if(clockwise)
    {
        clockwise = false;
        Scene_PushEvent(EVENT_PULSE_CLOCKWISE,0);
    }
    
    if(anticlockwise)
    {
        anticlockwise = false;
        Scene_PushEvent(EVENT_PULSE_ANTICLOCKWISE,0);
    } 
}


void CheckKnobSpeedReset(void)
{
    sysCB.knobPulseTimes = 0;
    Timer_GetSysTick(&sysCB.knobLastTick);
}

u8 CheckKnobSpeed(void)
{
    u8 speed = 0; 
        
    if(Timer_GetIntervalTime(sysCB.knobLastTick) > 50)
    {
        sysCB.knobPulseTimes = 0;
        speed = 0;
    }
    else
    {
        if(sysCB.knobPulseTimes < 3)
        {
            speed = 0;
            sysCB.knobPulseTimes++;
        }
        else
            speed = 1;
    }
    Timer_GetSysTick(&sysCB.knobLastTick);
    return speed;
}

